const app = getApp()

let tapVal = [];
Page({
    data: {
        isKeyboard: false, // 键盘
        provinceArr: ["粤", "京", "津", "渝", "沪", "冀", "晋", "辽", "吉", "黑", "苏", "浙", "皖", "闽", "赣", "鲁", "豫", "鄂", "湘", "琼", "川", "贵", "云", "陕", "甘", "青", "蒙", "桂", "宁", "新", "藏", "使", "领", "警", "学", "港", "澳"],
        keyboardNumber: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
        strArr: ["Q", "W", "E", "R", "T", "Y", "U", "P", "A", "S", "D", "F", "G", "H", "J", "K", "L", "Z", "X", "C", "V", "B", "N", "M"],
        hiddenPro: false, // 省份键盘
        hiddenStr: true, // 数字字母键盘
        carNum: 'A', // 车票其他字母数字
        provinces: '豫', // 车牌上的省简称
        unique: false, // 数字键盘是否可点
        clearShow: true, // 键盘关闭icon
        useNature: [{
                name: '非营运车',
                checked: true,
            },
            {
                name: '营运车',
                checked: false,
            }
        ],
        seatsNum: [{
                name: '5座以下',
                checked: true,
            },
            {
                name: '5座',
                checked: false
            },
            {
                name: '6座',
                checked: false
            },
            {
                name: '7座',
                checked: false
            },
            {
                name: '8/9座',
                checked: false
            },
            {
                name: '9座以上',
                checked: false
            },
        ],
        isAccident: [{
                name: '是',
                checked: false
            },
            {
                name: '否',
                checked: false
            },
        ],     
        date: '请选择注册日期',
    },

    // 座位数
    seatsRadio: function (e) {
        let _this = this
        var index = e.currentTarget.dataset.seatsindex; //获取当前点击的下标
        var checkboxArr = _this.data.seatsNum; //选项集合
        console.log(_this.data.seatsNum)
        if (checkboxArr[index].checked) return; //如果点击的当前已选中则返回
        checkboxArr.forEach(item => {
            item.checked = false
        })
        checkboxArr[index].checked = true; //改变当前选中的checked值
        _this.setData({
            seatsNum: checkboxArr,
        });
    },
    //使用性质
    useRadio: function (e) {
        let _this = this
        var index = e.currentTarget.dataset.useindex; //获取当前点击的下标
        var checkboxArr = _this.data.useNature; //选项集合
        console.log(_this.data)
        if (checkboxArr[index].checked) return; //如果点击的当前已选中则返回
        checkboxArr.forEach(item => {
            item.checked = false
        })
        checkboxArr[index].checked = true; //改变当前选中的checked值
        _this.setData({
            useNature: checkboxArr,
        });
    },
    //是否有人伤事故
    accidentRadio: function (e) {
        let _this = this
        var index = e.currentTarget.dataset.accidentindex; //获取当前点击的下标
        var checkboxArr = _this.data.isAccident; //选项集合
        console.log(_this.data)
        if (checkboxArr[index].checked) return; //如果点击的当前已选中则返回
        checkboxArr.forEach(item => {
            item.checked = false
        })
        checkboxArr[index].checked = true; //改变当前选中的checked值
        _this.setData({
            isAccident: checkboxArr,
        });
    },
    //点击省份
    provincesClick: function () {
        this.setData({
            isKeyboard: true,
            hiddenPro: false,
            hiddenStr: true,
        })
    },
    proTap(e) {
        let province = e.currentTarget.dataset.province;
        this.setData({
            provinces: province,
            hiddenPro: true,
            hiddenStr: true,
            isKeyboard: false
        })
    },
    //点击字母数字
    numClick: function () {
        this.setData({
            isKeyboard: true,
            hiddenPro: true,
            hiddenStr: false,
        })
    },
    strTap(e) {
        let _this = this;
        let province = e.currentTarget.dataset.str;
        let carNum = _this.data.carNum;
        if (carNum.length > 6) return false; // 车牌长度最多为7个（新能源车牌7个）
        carNum += province;
        tapVal.push(province)
        this.setData({
            carNum: carNum
        });
        if (tapVal.length > 0) {
            _this.setData({
                unique: false,
                clearShow: true
            })
        } else {
            _this.setData({
                unique: true,
                clearShow: false
            })
        };
    },
    backSpace() { //退格
        let _this = this
        let carNum = this.data.carNum;
        tapVal.pop()
        console.log(tapVal)
        var arr = carNum.split('');
        arr.splice(-1, 1)
        var str = arr.join('')
        // if (str == '') {
        //     this.setData({
        //         hiddenPro: false,
        //         hiddenStr: true
        //     })
        // }
        this.setData({
            carNum: str
        })
        if (tapVal.length === 0) {
            _this.setData({
                unique: true,
                clearShow: false
            })
        }
    },
    defineKeyboard() { //确定
        this.setData({
            hiddenPro: true,
            hiddenStr: true,
            isKeyboard: false
        })
    },
    cleraClick: function () {
        this.setData({
            clearShow: false,
            carNum: ''
        })
    },
    // 日期选择
    bindDateChange: function(e) {
        this.setData({
            date: e.detail.value
        })
    },
})